
export default {
  name: "Sidebar",
  data() {
    return {
      chooseIndex: 0,
      secondIndex: 0,
      sidebarList: [
        {
          name: "information",
          isOpen: 1,
          bar: '无',
          secondBar: [
            {
              name: "web information",
              bar: 'webinfo',
            }, {
              name: "poetry action",
              bar: 'poetry',
            }, {
              name: "update log",
              bar: 'updateNote',
            },
          ]
        }, {
          name: "photo",
          isOpen: 0,
          bar: '无',
          secondBar: [
            {
              name: "picture",
              bar: 'picture',
            },
          ]
        }, {
          name: "导航3",
          isOpen: 0,
          bar: '无',
        },
      ]
    }
  },
  methods: {
    /**
     * sidebar点击切换事件
     * 通过isOpen判断是否展开项目
     * XXX.bar发送给主界面是要展开那个页面
     * @param {Interger} index 主要点击index或者子项目点击index
     * @param {String} type 区分是为主项目点击还是子项目
     */
    toggleBar(index, type) {
      if (type === 'main') {
        this.chooseIndex = index;
        this.secondIndex = 0;
        if(this.sidebarList[index].isOpen !== 1) {
          this.sidebarList.map((i) => {
            i.isOpen = 0;
          });
          this.sidebarList[index].isOpen = 1;
        } else {
          this.sidebarList[index].isOpen = 0;
        }
        this.$emit('changePanel', this.sidebarList[this.chooseIndex].secondBar[this.secondIndex].bar);
      } else {
        this.secondIndex = index;
        this.$emit('changePanel', this.sidebarList[this.chooseIndex].secondBar[this.secondIndex].bar);
      }
    }
  }
}
